﻿using UnityEngine;
using System.Collections;

namespace UI
{
    public class RushSweepResultItem : RushSweepItemBase 
    {
        public UISprite smallIcon;
        public UILabel floorLabel;
        public UILabel resultLabel;
        public UILabel pointNumLabel;
        public UILabel coinNumLabel;

        public float height;

        public override float GetHeight()
        {
            return height;
        }

        public void Init(int floor, ProtoBuf.Message.ResultObject gain) {
            SetFloor(floor);
            pointNumLabel.text = GetGainPoint(gain).ToString();
            coinNumLabel.text = GetGainCoin(gain).ToString();
            resultLabel.gameObject.SetActive(false);
        }

        public void Init(int floor, bool isPassed, ProtoBuf.Message.ResultObject gain) {
            SetFloor(floor);
            pointNumLabel.text = GetGainPoint(gain).ToString();
            coinNumLabel.text = GetGainCoin(gain).ToString();
            if (isPassed) {
                resultLabel.text = "Pass";
            }
            else
            {
                resultLabel.text = "No Pass";
            }
        }

        void SetFloor(int floor) {
            floorLabel.text = string.Format(TableTextBlo.GetText("di_x_ceng"), floor);
            if (floor % 3 == 0)
            {
                smallIcon.spriteName = "UI_item_title_men_blue";
            }
            else if (floor % 3 == 1)
            {
                smallIcon.spriteName = "UI_item_title_men_green";
            }
            else if (floor % 3 == 2)
            {
                smallIcon.spriteName = "UI_item_title_men_zi";
            }
        }

        int GetGainPoint(ProtoBuf.Message.ResultObject gain) {
            foreach (var g in gain.simps) {
                if (g.id == Dict.Config.TableConst.point) {
                    return g.num;
                }
            }
            return 0;
        }

        int GetGainCoin(ProtoBuf.Message.ResultObject gain) {
            foreach (var g in gain.simps) {
                if (g.id == Dict.Config.TableConst.coin) {
                    return g.num;
                }
            }
            return 0;
        }

    }
}